﻿using MediatR;
using Traceability.App.Apilication.Common;
using Traceability.App.DTOS;
using Traceability.Domain;
using Traceability.ErrorCode;
using Traceability.Infrastructure.Interfance;

namespace Traceability.App.Apilication.Handler
{
    public class GetGoodsHandler : IRequestHandler<GetGoodsCommon, ApiResult<List<GoodsDTO>>>
    {
        private readonly IBaseRespository<GoodsModel> goodsRepo;

        public GetGoodsHandler(IBaseRespository<GoodsModel> goodsRepo)
        {
            this.goodsRepo = goodsRepo;
        }

        public Task<ApiResult<List<GoodsDTO>>> Handle(GetGoodsCommon request, CancellationToken cancellationToken)
        {
            ApiResult<List<GoodsDTO>> res = new ApiResult<List<GoodsDTO>>();

            var info = goodsRepo.GetAll().Select(x=>new GoodsDTO()
            {
                Goods_ID=x.Goods_ID,
                Goods_Name=x.Goods_Name,
            }).ToList();

            res.Code=ApiEnum.Success;
            res.Message = "商品名称下拉框";
            res.Data = info;
            return Task.FromResult(res);


        }
    }
}
